package com.heima.tlias.service.impl;

import com.heima.tlias.anno.Log;
import com.heima.tlias.dao.DeptMapper;
import com.heima.tlias.pojo.Dept;
import com.heima.tlias.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Administrator
 */
//@Scope("prototype")
@Service
@Slf4j
@Lazy
//@RequiredArgsConstructor
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> getDeptList() {
        String threadName = Thread.currentThread().getName();
        log.info("DeptServiceImpl 当前线程名称:{}",threadName);

        List<Dept> deptList = deptMapper.queryList();
        //int i = 10/0;
        return deptList;
    }

    @Override
    @Log
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    @Log
    public void insert(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        dept.setCreateTime(LocalDateTime.now());
        //调用数据访问层保存数据到数据库
        deptMapper.insert(dept);
    }

    @Override
    public Dept queryById(Integer id) {
        Dept dept = deptMapper.queryById(id);
        return dept;
    }

    @Override
    @Log
    public void updateById(Dept dept) {
        //补全属性
        dept.setUpdateTime(LocalDateTime.now());
        //调用数据访问层更新数据
        deptMapper.updateById(dept);
    }
}
